package com.example.demo.domain.base;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import lombok.Getter;

import java.util.List;

/**
 * PageResult
 *
 * @author hao.chen
 * @date 2023/5/30 9:47
 */
@Getter
public class PageResult<T> {

    /** 分页结果 */
    private final List<T> list;
    /** 分页大小 */
    private final int pageSize;
    /** 分页页码 */
    private final int pageNum;
    /** 总记录数 */
    private final Long total;

    public PageResult(PageInfo<T> pageInfo) {
        this.list = pageInfo.getList();
        this.pageSize = pageInfo.getPageSize();
        this.pageNum = pageInfo.getPageNum();
        this.total = pageInfo.getTotal();
    }

    public PageResult(Page<T> pageInfo) {
        this.list = pageInfo.getRecords();
        this.pageSize = (int) pageInfo.getSize();
        this.pageNum = (int) pageInfo.getCurrent();
        this.total = pageInfo.getTotal();
    }
}
